import { GalleryVerticalEnd } from "lucide-react";
import { LoginForm } from "@/components/login-form";
import placeholderImage from "@/assets/placeholder.svg";
import type { LoginData } from "@/api/login/types";
import useAuthStore from "@/store/auth";
import { useNavigate } from "react-router-dom";

export default function LoginPage() {
  const login = useAuthStore((s) => s.login);
  const navigate = useNavigate();

  const handleLogin = async (data: LoginData) => {
    try {
      const loginData = {...data, tenantId: "000000" };
      await login(loginData); // 调用 zustand store 里的 login
      navigate("/home");
    } catch (err) {
      console.log("登录失败", err);
    }
  };

  return (
    <div className="grid min-h-svh lg:grid-cols-2">
      <div className="flex flex-col gap-4 p-6 md:p-10">
        <div className="flex justify-center gap-2 md:justify-start">
          <a href="#" className="flex items-center gap-2 font-medium">
            <div className="bg-primary text-primary-foreground flex size-6 items-center justify-center rounded-md">
              <GalleryVerticalEnd className="size-4" />
            </div>
            法盾智能审查
          </a>
        </div>
        <div className="flex flex-1 items-center justify-center">
          <div className="w-full max-w-xs">
            <LoginForm onSubmit={handleLogin} />
          </div>
        </div>
      </div>
      <div className="bg-muted relative hidden lg:block">
        <img
          src={placeholderImage}
          alt="Image"
          className="absolute inset-0 h-full w-full object-cover dark:brightness-[0.2] dark:grayscale"
        />
      </div>
    </div>
  );
}
